<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>销售流水</title>
		<link rel="stylesheet" href="__PEAR__/component/pear/css/pear.css" />
		<style>
		.layui-input{width:150px;}
		.layui-form-label{width:auto;}
		.layui-form-item .layui-input-inline{width: 150px;}
		.inputdiv{display:flex;height: 38px;line-height: 38px;}
		.inputdiv i{position:absolute;right:10px;}
		.layui-table-cell .layui-table-link {color: #ff6a08!important;}}
		</style>
	</head>
	<body class="pear-container">
		<div class="layui-card">
			<div class="layui-card-body">
				<form class="layui-form" action="">
					<div class="layui-form-item">
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline" id="date-range">
							<label class="layui-form-label">日期范围</label>
							<div class="layui-input-inline">
					          <input type="text" name="start" value="" autocomplete="off" id="start-date" class="layui-input" placeholder="开始日期">
					        </div>
					        <div class="layui-form-mid">-</div>
					        <div class="layui-input-inline">
					          <input type="text" name="end" value="" autocomplete="off" id="end-date" class="layui-input" placeholder="结束日期">
					        </div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">快速设置</label>
							<div class="layui-input-inline">
								<select lay-filter="getdate">
									<option value="0">全部</option>
									<option value="1">今天</option>
									<option value="2">昨天</option>
									<option value="3">本周</option>
									<option value="4">上周</option>
									<option value="5">本月</option>
									<option value="6">上月</option>
									<option value="7">本季</option>
									<option value="8">上季</option>
									<option value="9">今年</option>
								</select>
							</div>
						</div>
						
					</div>
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
								<label class="layui-form-label">分店仓库</label>
								<div class="layui-input-inline inputdiv">
									<input type="text" name="branch_no" id="branch_no" autocomplete="off" value="" placeholder="" class="layui-input" onfocus="showBranchs()">
									<i class="layui-icon layui-icon-home"></i>
								</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">营业员号</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="oper_id" id="operator" placeholder=""  autocomplete="off" class="layui-input" onfocus="showOperators()">
								<i class="layui-icon layui-icon-username"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">POS机号</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="pos_id" id="posid" placeholder="" autocomplete="off" class="layui-input" onfocus="showPos()">
								<i class="layui-icon layui-icon-diamond"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">赠送方式</label>
							<div class="layui-input-inline">
								<select name="sale_way">
									<option selected="selected" value="">全部</option>
	                                <option value="A">销售</option>
	                                <option value="B">退货</option>
	                                <option value="C">赠送</option>
								</select>
							</div>
						</div>
					</div>
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品货号</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="item_no" id="item_no" placeholder="" autocomplete="off" class="layui-input" onfocus="selectGoods()">
								<i class="layui-icon layui-icon-cart-simple"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品分类</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="item_clsno" id="item_cls" placeholder="" autocomplete="off" class="layui-input" onfocus="selectCls()">
								<i class="layui-icon layui-icon-list"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品品牌</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="item_brand" id="brand" placeholder="" autocomplete="off" class="layui-input" onfocus="selectBrand()">
								<i class="layui-icon layui-icon-vercode"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">单据编号</label>
							<div class="layui-input-inline">
								<input type="text" name="flow_no" placeholder="" class="layui-input">
							</div>
						</div>
					</div>
					
					<div class="layui-row">
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">供应商名</label>
							<div class="layui-input-inline inputdiv">
								<input type="text" name="supcust_no" id="supplier" placeholder="" autocomplete="off" class="layui-input" onfocus="showSupplier()">
								<i class="layui-icon layui-icon-username"></i>
							</div>
						</div>
						
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">会员编号</label>
							<div class="layui-input-inline">
								<input type="text" name="vip_no" placeholder="" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<label class="layui-form-label">商品名称</label>
							<div class="layui-input-inline">
								<input type="text" name="item_name" placeholder="" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-form-item layui-inline">
							<button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="saleflow-query">
								<i class="layui-icon layui-icon-search"></i>
								查询
							</button>
							<button type="reset" class="pear-btn pear-btn-md" onclick="resetForm()">
								<i class="layui-icon layui-icon-refresh"></i>
								重置
							</button>
						</div>
					</div>
					
					</div>
					
				</form>
			</div>
		</div>
		<div class="layui-card">
			<div class="layui-card-body" id="saleflow-body">
				<table id="saleflow-table" lay-filter="saleflow-table"></table>
			</div>
		</div>
		<script type="text/html" id="saleflowTpl">
  			<a onclick="showFlow('{{d.flow_no}}')" class="layui-table-link" target="_self">{{ d.flow_no }}</a>
		</script>
		<script src="__STATIC__/lib/layui/layui.js"></script>
		<script src="__PEAR__/component/pear/pear.js"></script>
		<script src="__STATIC__/js/admin/common.js"></script>
		<script>
			var branch_no="";
			var _layerIndex=null;
			var operator_url="{:U('Controls/operators')}";
			var supplier_url="{:U('Controls/suppliers')}";
			var pos_url="{:U('Controls/poslists')}";
			var items_url="{:U('Controls/items')}";
			var itemcls_url="{:U('Controls/itemcls')}";
			var brand_url="{:U('Controls/brands')}";
			var branchs_url="{:U('Controls/branchs')}";
			
			layui.use(['table', 'form', 'jquery','common','laydate'], function() {
				let table = layui.table;
				let form = layui.form;
				let $ = layui.jquery;
				let common = layui.common;
				let laydate = layui.laydate;
				
			  	laydate.render({
					    elem: '#date-range'
					    ,range: ['#start-date', '#end-date']
			    });

				let DATA_PATH = "/{$MODULE_NAME}/pos/saleflow/";

				let cols = [
					[
						{
							title: '序号',
							field: 'rowIndex',
							align: 'left',
							width: 80
						},
						{
							title: '门店编号',
							field: 'branch_no',
							align: 'left',
							width: 100
						},
						{
							title: '门店名称',
							field: 'branch_name',
							align: 'left',
							width: 100
						},
						{
							title: '单据编号',
							field: 'flow_no',
							align: 'left',
							templet:'#saleflowTpl',
							width: 180
						},
						{
							title: '操作日期',
							field: 'oper_date',
							align: 'left',
							width: 160
						},
						{
							title: '商品名称',
							field: 'item_name',
							align: 'left',
							width: 120
						},
						{
							title: '货号',
							field: 'item_no',
							align: 'left',
							width: 120
						},
						{
							title: '单位',
							field: 'unit_no',
							align: 'center',
							width: 100
						},
						{
							title: '规格',
							field: 'item_size',
							align: 'center',
							width: 100
						},
						{
							title: '销售方式',
							field: 'sell_way',
							align: 'center',
							width: 100
						},
						{
							title: '数量',
							field: 'sale_qnty',
							align: 'center',
							width: 100
						},
						{
							title: '售价',
							field: 'sale_price',
							align: 'center',
							width: 100
						},
						{
							title: '售价金额',
							field: 'sale_money',
							align: 'center',
							width: 100
						},
						{
							title: '原价',
							field: 'unit_price',
							align: 'center',
							width: 100
						},
						{
							title: '原价金额',
							field: 'unit_money',
							align: 'center',
							width: 100
						},
						{
							title: '进价',
							field: 'in_price',
							align: 'center',
							width: 100
						},
						{
							title: '进价金额',
							field: 'in_money',
							align: 'center',
							width: 100
						},
						{
							title: '自编码',
							field: 'item_subno',
							align: 'center',
							width: 100
						},
						{
							title: '分类编码',
							field: 'item_clsno',
							align: 'center',
							width: 100
						},
						{
							title: '分类名称',
							field: 'item_clsname',
							align: 'center',
							width: 100
						},
						{
							title: '品牌',
							field: 'item_brand',
							align: 'center',
							width: 100
						},
						{
							title: '品牌名称',
							field: 'item_brandname',
							align: 'center',
							width: 100
						},
						{
							title: 'POS机编码',
							field: 'pos_id',
							align: 'center',
							width: 100
						},
						{
							title: '收银员',
							field: 'oper_name',
							align: 'center',
							width: 100
						},
						{
							title: '会员编号',
							field: 'vip_no',
							align: 'center',
							width: 100
						},
						{
							title: '备注',
							field: 'memo',
							align: 'center',
							width: 100
						},
						{
							title: '折扣值',
							field: 'discount_rate',
							align: 'center',
							width: 100
						}
					]
				]

				table.render({
					elem: '#saleflow-table',
					url: DATA_PATH+"search",
					page: true,
					cols: cols,
					height:600,
					skin: 'line',
					toolbar: '',
					defaultToolbar: [],
					done:function(res, curr, count){
						var _width=$("#saleflow-body").width();
						$("#saleflow-table").css("width", _width);
					}
				});

				form.on('select(getdate)', function(data) {
					date = new Array(2);
					var selc=parseInt(data.value);
		            switch (selc)
		            {
		            	case 1://当前天
	                    	date[0] = '{php}echo date('Y-m-d');{/php}';
	                    	date[1] = '{php}echo date('Y-m-d');{/php}';
	                    break;
		                case 2://昨天
		                    date[0] = '{php}echo date('Y-m-d', strtotime('-1 day'));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', strtotime('-1 day'));{/php}';
		                    break;
		                case 3://本周
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y")));{/php}';
		                    break;
		                case 4://上周
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y")));{/php}';
		                    break;
		                case 5://本月
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m"),1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,date("m"),date("t"),date("Y")));{/php}';
		                    break;
		                case 6://上月
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0 , 0,date("m")-1,1,date("Y")));{/php}';
		                    date[1] = '{php}echo date('Y-m-d',mktime(23,59,59,date("m") ,0,date("Y")));{/php}';
		                    break;
		                case 7://本季度
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0,0,ceil((date('n'))/3)*3-3+1,1,date('Y')));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,ceil((date('n'))/3)*3,date('t',mktime(0, 0 ,0,ceil((date('n'))/3)*3,1,date("Y"))),date('Y')));{/php}';
		                    break;
		                case 8://上季度
		                    date[0] = '{php}echo date('Y-m-d', mktime(0, 0,0,(ceil((date('n'))/3)-1)*3-3+1,1,date('Y')));{/php}';
		                    date[1] = '{php}echo date('Y-m-d', mktime(23,59,59,(ceil((date('n'))/3)-1)*3,date('t',mktime(0, 0 ,0,(ceil((date('n'))/3)-1)*3,1,date("Y"))),date('Y')));{/php}';
		                    break;
		                case 9://本年
		                    date[0] = '{php}echo date('Y-01-01');{/php}';
		                    date[1] = '{php}echo date('Y-12-31');{/php}';
		                    break;
		            }
		            $('#start-date').val( date[0]);
	                $('#end-date').val(date[1]);
				});
				
				form.on('submit(saleflow-query)', function(data) {
					table.reload('saleflow-table', {
						where: data.field,
						page:{curr:1}
					})
					return false;
				});
				
				//显示分店选择框
				window.showBranchs=function(){
					_layerIndex=openWin("分店仓库选择",branchs_url,"800px","600px");
				}
				
				//门店选择后的回调函数
				window.callBackBranch=function(data){
					
					var arr=new Array();
					for(var i in data){
						arr.push(data[i]['branch_no']);
					}
					
					$("#branch_no").val(arr.join(","));
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
					_layerIndex=null;
				}
				
				//显示操作员选择框
				window.showOperators=function(){
					var oval=$("#operator").val();
					
					if(_layerIndex==null||oval==''){
						_layerIndex=openWin("营业员选择",operator_url,"800px","600px");
					}
				}
				
				//操作员选择后的回调函数
				window.callBackOprator=function(data){
					
					$("#operator").val(data[0]['oper_id']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}
				
				//显示POS机选择框
				window.showPos=function(){
					var oval=$("#posid").val();
					
					if(_layerIndex==null||oval==''){
						_layerIndex=openWin("POS机选择",pos_url,"800px","600px");
					}
				}
				
				//POS机选择后的回调函数
				window.callBackPos=function(data){
					
					$("#posid").val(data[0]['posid']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}
				
				//选择商品窗口
				window.selectGoods=function(){
					_layerIndex=openWin("商品选择",items_url,"1100px","600px");
				}
				
				//商品选择后的回调函数
				window.callBack=function(data){
					
					$("#item_no").val(data[0]['item_no']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//选择商品分类窗口
				window.selectCls=function(){
					_layerIndex=openWin("商品分类选择",itemcls_url,"800px","600px");
				}
				
				//商品分类选择后的回调函数
				window.callBackItemcls=function(data){
					
					$("#item_cls").val(data[0]['item_clsno']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//选择商品品牌窗口
				window.selectBrand=function(){
					_layerIndex=openWin("商品品牌选择",brand_url,"800px","600px");
				}
				
				//商品品牌选择后的回调函数
				window.callBackBrand=function(data){
					
					$("#brand").val(data[0]['code_id']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
					}
				}
				
				//显示供应商选择框
				window.showSupplier=function(){
					_layerIndex=openWin("供应商选择",supplier_url,"800px","600px");
				}
				
				//供应商选择后的回调函数
				window.callBackSupplier=function(data){
					
					$("#supplier").val(data[0]['sp_no']);
					
					if(_layerIndex!=null){
						layer.close(_layerIndex);
						_layerIndex=null;
					}
				}

				//打开详细页面
				window.showFlow=function(flowno){
					openWin("销售流水详细",DATA_PATH+'saleDetail/flowno/'+flowno,"800px","500px");
				}
				
				window.refresh = function(param) {
					table.reload('saleflow-table');
				}
			})
		</script>
	</body>
</html>
